package com.chang.rentmall.controllers;

import com.chang.rentmall.beans.MessageBean;
import com.chang.rentmall.forms.OrderFormBean;
import com.chang.rentmall.servicesImpl.OrderServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OrderController {
    @Autowired
    OrderServiceImpl orderService;

    @RequestMapping(value = "/order/create", method = {RequestMethod.POST})
    public MessageBean createOrder (@RequestBody OrderFormBean orderFormBean) {
        return orderService.addOrder(orderFormBean.getForm());
    }

    @RequestMapping(value = "/order/update", method = {RequestMethod.POST})
    public MessageBean updateOrder (@RequestBody OrderFormBean orderFormBean) {
        return orderService.updateOrder(orderFormBean.getForm());
    }

    @RequestMapping(value = "/order/customer/list", method = {RequestMethod.POST})
    public MessageBean getCustomersByShop (@RequestBody OrderFormBean orderFormBean) {
        return orderService.getCustomersByShop(orderFormBean);
    }

    @RequestMapping(value = "/order/customer/shop/list", method = {RequestMethod.POST})
    public MessageBean getUserOrdersByShop(@RequestBody OrderFormBean orderFormBean) {
        return orderService.getShopOrdersByUser(orderFormBean);
    }

    @RequestMapping(value = "/order/user/list", method = {RequestMethod.POST})
    public MessageBean getUserOrders(@RequestBody OrderFormBean orderFormBean) {
        return orderService.getOrdersByUser(orderFormBean);
    }

    @RequestMapping(value = "/order/delete", method = {RequestMethod.POST})
    public MessageBean deleteOrder (@RequestBody OrderFormBean orderFormBean) {
        return orderService.deleteOrder(orderFormBean);
    }

    @RequestMapping(value = "/order/detail", method = {RequestMethod.POST})
    public MessageBean getOrderDetail (@RequestBody OrderFormBean orderFormBean) {
        return orderService.getOrderByNumber(orderFormBean);
    }
}
